package world.hezi.handlers;

import net.mamoe.mirai.contact.Contact;
import net.mamoe.mirai.event.EventHandler;
import net.mamoe.mirai.event.ListeningStatus;
import net.mamoe.mirai.event.SimpleListenerHost;
import net.mamoe.mirai.event.events.MessageEvent;
import net.mamoe.mirai.message.data.Image;
import net.mamoe.mirai.message.data.Message;
import net.mamoe.mirai.message.data.MessageChain;
import net.mamoe.mirai.message.data.MessageChainBuilder;
import org.jetbrains.annotations.NotNull;
import org.opencv.imgcodecs.Imgcodecs;
import world.hezi.entity.SIFTResponse;
import world.hezi.utils.OpenCvUtil;
import world.hezi.utils.PicturesUtil;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.TimerTask;
import java.util.UUID;

/**
 * @author wangzijian
 * @since 2023/12/4 10:12
 */
public class DiaoPicHandlers extends SimpleListenerHost {

    private static final List<Long> ALLOW = Arrays.asList(651343119L
            , 649538504L
            , 981566412L
            ,730451715L
            ,247133571L
            ,790611872L
//            ,655620062L
    );
    @NotNull
    @EventHandler
    public ListeningStatus onMessage(@NotNull MessageEvent event) {
//        if (!ALLOW.contains(event.getSource().getSubject().getId())){
//            return ListeningStatus.LISTENING;
//        }
        String message = event.getMessage().contentToString();
        if (message.equals("每日弔图")){
            File diaoDir = new File("D:\\haha");
            File[] files = diaoDir.listFiles();
            try {
                Contact contact = event.getSubject();
                MessageChainBuilder messages = new MessageChainBuilder();
                Image image = PicturesUtil.uploadAndGetImage(files[(int) (files.length* Math.random())], contact);
                MessageChain build = messages
                        .append("每日弔图")
                        .append(image)
                        .build();
                contact.sendMessage(build);
            }catch (Exception e){
                e.printStackTrace();
            }
        }

        return ListeningStatus.LISTENING;
    }
}
